<?php
/**
* @author: Nguyen Thanh Tung
* @date: Friday, January 24, 2014
*/

/**
* Not login
* Not permission
*
* Note: only root, administrator, leader with permission user module
*/
if( !isset($AppUI) || !isset($_SESSION['user'])) {redirect(HOST_BACKEND);}
  
$this->load->model('user_model', 'user');	

$intTotal   = 0;
$intPage    = $this->input->get('page', 1);
$intStatus  = $this->input->get('stt', -1);
$intOptionSearch  = $this->input->post('optionsearch',0);
$strDateStart   = $this->input->get('startdate', '');
$strDateEnd     = $this->input->get('enddate', '');
$intCancel	= $this->input->get('pcancel', 0);
$strKeyword	= $this->input->get('pkeyword','');
$intLimit   = 20;
$intOffset  = ($intPage-1)*$intLimit;
//kiem tra dateStart va dateEnd
//if($strDateStart != '' || $strDateEnd != ''||$intOptionSearch!=0||$strKeyword!=''||$intStatus!=-1) {
if($strDateStart != '' || $strDateEnd != ''||$intStatus!=-1) {	
	$_SESSION['USER_CANCEL'] 	= 1;	
	$_SESSION['USER_SEARCH']	= $this->input->get();
}elseif($intOptionSearch!=''||$intStatus!=-1){
	$_SESSION['USER_CANCEL'] 	= 1;	
	$_SESSION['USER_SEARCH']	= $this->input->get();
}
elseif(trim($strKeyword)!=''||$intStatus!=-1){
	$_SESSION['USER_CANCEL'] 	= 1;	
	$_SESSION['USER_SEARCH']	= $this->input->get();
}
else {
	if(isset($_SESSION['USER_SEARCH'])) unset($_SESSION['USER_SEARCH']);
	if(isset($_SESSION['USER_CANCEL'])) unset($_SESSION['USER_CANCEL']);
    $strDateStart = '';
    $strDateEnd = '';
	$intOptionSearch = 0;
	$strKeyword = '';
	$intStatus = -1;
}

if($intCancel) {
	if(isset($_SESSION['USER_SEARCH'])) unset($_SESSION['USER_SEARCH']);
	if(isset($_SESSION['USER_CANCEL'])) unset($_SESSION['USER_CANCEL']);
    $strDateStart = '';
    $strDateEnd = '';
	$intOptionSearch = 0;
	$strKeyword = '';
	$intStatus = -1;
}

$arrResult	= $this->user->getAll($AppUI->id, $intStatus, $intOptionSearch, $strKeyword, $strDateStart, $strDateEnd, 
																		$intOffset, $intLimit,$intTotal);
$this->smarty->assign('arrResult',  $arrResult);
$this->smarty->assign('intTotal',   $intTotal);
$this->smarty->assign('intOffset',  $intOffset);
$this->smarty->assign('intLimit',   $intLimit);

$this->smarty->display('user/index.tpl');